
package cc.md888.app.utils;

import java.util.Random;

public class RandomUserAgent {

    //Mozilla/5.0 (Linux; Android 7.0) AppleWebKit/535.0 (KHTML, like Gecko) Chrome/62.0.802.0 Safari/535.0
    private static final String[] ANDROID_VERSIONS = {"5.0", "6.0", "7.0", "8.0", "10.0", "11.0", "12.0" ,  "13.0",  "14.0",  "15.0",  "16.0"};
    private static final String[] WEBKIT_VERSIONS = {"535.0", "535.1", "534.2", "536.0", "534.2", "537.0"};
    private static final String[] CHROME_VERSIONS = {"126.0.6478.186", "127.0.6493.0", "126.0.6478.17", "127.0.6497.0"};


    public static String getRandomUserAgent() {
        Random random = new Random();
        StringBuilder userAgent = new StringBuilder("Mozilla/5.0 (Linux; Android %s) AppleWebKit/%s (KHTML, like Gecko) Chrome/%s");
        String androidVersion = ANDROID_VERSIONS[random.nextInt(ANDROID_VERSIONS.length)];
        String webKitVersion = WEBKIT_VERSIONS[random.nextInt(WEBKIT_VERSIONS.length)];
        String chromeVersion = CHROME_VERSIONS[random.nextInt(CHROME_VERSIONS.length)];
        return String.format(
                userAgent.toString(),
                androidVersion,
                webKitVersion,
                chromeVersion
        );
    }
 
    public static void main(String[] args) {
        System.out.println(getRandomUserAgent());
    }
}